home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / SLList.h < prev    next >
C/C++ Source or Header  |  1997-01-29  |  3KB  |  98 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988, 1992 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. #ifndef _SLList_h
  20. #define _SLList_h 1
  21.  
  22. #if defined (__GNUG__)
  23. #pragma interface
  24. #endif
  25.  
  26. #include <Pix.h>
  27.  
  28. #include "BaseSLList.h"
  29.  
  30. template<class T>
  31. class SLNode : public BaseSLNode
  32. {
  33.   public:
  34.     T                    hd; // Data part of node
  35.                          SLNode() { }
  36.                          SLNode(const T& h, SLNode* t = 0)
  37.                  : hd(h) { tl = t; }
  38.                          ~SLNode() { }
  39. };
  40.  
  41. template <class T>
  42. class SLList : public BaseSLList
  43. {
  44.   private:
  45.     virtual void delete_node(BaseSLNode *node) { delete (SLNode<T>*)node; }
  46.     virtual BaseSLNode* copy_node(const void *datum)
  47.     { return new SLNode<T>(*(const T*)datum); }
  48.     virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; }
  49.  
  50. public:
  51.     SLList() : BaseSLList() { }
  52.     SLList(const SLList<T>& a) : BaseSLList() { copy(a); }
  53.     SLList<T>&            operator = (const SLList<T>& a)
  54.     { BaseSLList::operator=((const BaseSLList&) a); return *this; }
  55.     ~SLList (void);
  56.  
  57.     Pix prepend(const T& item) {return BaseSLList::prepend(&item);}
  58.     Pix append(const T& item) {return BaseSLList::append(&item);}
  59.     Pix prepend(SLNode<T>* node) {return BaseSLList::prepend(node);}
  60.     Pix append(SLNode<T>* node) {return BaseSLList::append(node);}
  61.  
  62.     T& operator () (Pix p) {
  63.     if (p == 0) error("null Pix");
  64.     return ((SLNode<T>*)(p))->hd; }
  65.     const T& operator () (Pix p) const {
  66.     if (p == 0) error("null Pix");
  67.     return ((SLNode<T>*)(p))->hd; }
  68.     inline Pix first() const { return (last == 0) ? 0 : Pix(last->tl); }
  69.     void next(Pix& p) const
  70.     { p = (p == 0 || p == last) ? 0 : Pix(((SLNode<T>*)(p))->tl); }
  71.     Pix ins_after(Pix p, const T& item)
  72.       { return BaseSLList::ins_after(p, &item); }
  73.     void join(SLList<T>& a) { BaseSLList::join(a); }
  74.     
  75.     T& front() {
  76.     if (last == 0) error("front: empty list");
  77.     return ((SLNode<T>*)last->tl)->hd; }
  78.     T& rear() {
  79.     if (last == 0) error("rear: empty list");
  80.     return ((SLNode<T>*)last)->hd; }
  81.     const T& front() const {
  82.     if (last == 0) error("front: empty list");
  83.     return ((SLNode<T>*)last->tl)->hd; }
  84.     const T& rear() const {
  85.     if (last == 0) error("rear: empty list");
  86.     return ((SLNode<T>*)last)->hd; }
  87.     int remove_front(T& x) { return BaseSLList::remove_front(&x); }
  88.     T remove_front() { T dst; BaseSLList::remove_front(&dst, 1); return dst; }
  89. };
  90.  
  91. #endif
  92.  
  93. /*
  94. ;;; Local Variables: ***
  95. ;;; mode: C++ ***
  96. ;;; End: ***
  97. */
  98.